package top.kaoshanji.p2ch15b;

/**
 * 代码清单-p2ch15b-466页a：线程处于BLOCKED状态对中断的反应
 * author kaoshanji
 * ^_^
 * create time 2025/2/24 19:03
 */
public class InterruptSynchronizedDemo {

    private static Object lock = new Object();

    private static class A extends Thread {

        @Override
        public void run() {
            synchronized (lock) {
                while (!Thread.currentThread().isInterrupted()) {}
            }
            System.out.println("exit");
        }
    }

    public static void test() throws InterruptedException {
        synchronized (lock) {
            A a = new A();
            a.start();
            Thread.sleep(1000);

            a.interrupt();
            a.join();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        test();
    }


}
